<template>
  <!-- 登录页 -->
  <div class="login-container">
    <div class="login-title">
      <div class="logo">
        <img src="@/assets/images/1.png" alt="">
      </div>
      <div class="title-right">
        <div class="title">欢 迎 来 到 博 维 智 能 办 公</div>
        <div class="en">Welcome to Bo Wei Office Operating System</div>
      </div>
    </div>
    <div class="login-content">
      <div class="login-centent-img">
        <img src="../../assets/images/1.png" alt="">
      </div>
      <el-form
        ref="loginForm"
        :model="loginForm"
        :rules="loginRules"
        class="login-form"
        auto-complete="on"
        label-position="left"
      >
        <h3 class="login-right-title">用户登录</h3>
        <el-form-item prop="phone">
          <span class="svg-container-1" />
          <el-input
            ref="phone"
            v-model="loginForm.phone"
            placeholder="请输入手机号"
            name="phone"
            type="text"
            tabindex="1"
            auto-complete="on"
          />
          <el-button class="form-button">发送验证码</el-button>
        </el-form-item>

        <el-form-item prop="code">
          <span class="svg-container" />
          <el-input
            ref="code"
            v-model="loginForm.code"
            placeholder="请输入密码"
            name="code"
            tabindex="2"
            auto-complete="on"
          />
        </el-form-item>

        <el-button
          class="loginBtn"
          style="width: 100%; margin-bottom: 30px"
          @click.native.prevent="handleLogin"
        >登录
        </el-button>
      </el-form>
    </div>
  </div>
</template>

<script>
import { validMobile } from '@/utils/validate'
export default {
  data() {
    const checkMobile = (rule, value, callback) => {
      if (validMobile(value)) {
        callback()
      } else {
        callback(new Error('请输入合法手机号'))
      }
    }
    return {
      loginForm: {
        phone: '13333333333',
        code: '123456'
      },
      loginRules: {
        phone: [
          {
            required: true, message: '手机号码不能为空', trigger: 'blur'
          },
          {
            validator: checkMobile, trigger: 'blur'
          }
        ],
        code: [
          {
            required: true, message: '验证码不能为空', trigger: 'blur'
          },
          {
            min: 4, max: 10, message: '验证码在4-10位之间', trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    async handleLogin() {
      // this.$router.push("/");
      try {
        // 校验表单
        await this.$refs.loginForm.validate()
        // 发起请求
        // await this.$store.dispatch('user/login', this.loginForm)
        // 提示用户
        this.$message.success('登录成功')
        // 跳转页面
        this.$router.push('/')
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="scss">
$bg: #283443;
$light_gray: #68b0fe; // 将输入框颜色改成蓝色
$cursor: #fff;

.login-container {
  background-color: #3672fb;
  background-position: center; // 将图片位置设置为充满整个屏幕
  background-size: cover;
  .el-input {
    display: inline-block;
    height: 42px;
    line-height: 42px;
    width: 210px;
    font-size: 20px;
    // background-color: pink;
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      height: 40px;
    }
  }
  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.7); // 输入登录表单的背景色
    border-radius: 5px;
    color: #454545;
  }
  .el-form-item__error {
    font-size: 14px;
    margin-left: 50px;
  }
}
</style>

<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  min-height: 100%;
  width: 100%;
  overflow: hidden;
  .login-title {
    width: 860px;
    height: 112px;
    // margin: 100px 554px 10px 554px;
    padding-top: 100px;
    margin: 0 auto;
    display: flex;
    .logo {
      width: 158px;
      height: 104px;
      color: $light_gray;
      background-color: #fff;

      text-align: center;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .title-right {
      color: $light_gray;
      width: 685px;
      .title {
        width: 685px;
        height: 70px;
        font-size: 50px;
        font-family: PingFang SC;
        font-weight: bold;
        display: flex;
        justify-content: center;
      }
      .en {
        width: 685px;
        height: 42px;
        font-size: 30px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-weight: 300;
        font-family: PingFang SC;
      }
    }
  }
  .login-content {
    width: 1264px;
    height: 624px;
    background: #ffffff;
    margin: 0 auto;
    border-radius: 30px;
    margin-top: 150px;
    display: flex;
    .login-centent-img {
      width: 554px;
      height: 554px;
      margin-top: 53px;
      margin-left: 30px;
    }
  }
  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 70px 35px 0;
    margin: 0 auto;
    overflow: hidden;
    .el-form-item {
      height: 70px;
      border-bottom: 2px solid #eee;
    }
    .login-right-title {
      margin-bottom: 80px;
      width: 160px;
      height: 56px;
      font-size: 40px;
      font-family: PingFang SC;
      font-weight: 400;
      line-height: 56px;
      color: #3672fb;
      opacity: 1;
    }
    .form-button {
      margin-left: 60px;
      width: 140px;
      height: 48px;
      background: #d6e3fe;
      font-weight: 600;
      border-radius: 40px;
      color: #3672fb;
    }
  }

  .svg-container {
    width: 26px;
    height: 30px;
    padding: 6px 5px 6px 15px;
    background: url("../../assets/images/yz.png") no-repeat;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }
  .svg-container-1 {
    width: 24px;
    height: 32px;
    padding: 6px 5px 6px 15px;
    background: url("../../assets/images/sj.png") no-repeat;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }
  .loginBtn {
    margin-top: 50px;
    background-color: #3672fb;
    height: 64px;
    line-height: 32px;
    font-size: 24px;
    color: #fff;
    border: 0;
  }
}
</style>
